'use strict';

const {
  Controller
} = require('egg');

/**
 * BaseController
 * @class
 * @author   
 */
class BaseController extends Controller {
  get user() {
    // return this.ctx.session.user;
  }

  success(data,message, status) {
    // console.log(this.ctx.SUCCESS_CODE,">>>",data,status)
    this.ctx.status =  200;
    // this.ctx.header={d:123}//不能加此
    this.ctx.body = {
      success: true,
      status: status || 1,
      ...data,
      msg:message||''
    };    
  }

  fail( message,status) {
    this.ctx.body = {
      success: false,
      status:status||0,
      msg:message||''
    };
    this.ctx.status = 200;
  }


  /**
   * 
   * @param {*} message 要返回的错误消息
   * status:4
   */
  validateFail(message,status){
   
    this.ctx.body = {
      success: false,
      status:4,
      msg:message||'验证失败'
    };
    this.ctx.status =status|| 200;//待确定状态码
  }

  notFound(msg) {
    msg = msg || 'not found';
    this.ctx.throw(404, msg);
  }

  
}

module.exports = BaseController;